<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.sinodata.bsm.center.dao.BaseDao"%>
<%@page import="com.sinodata.bsm.common.vo.Res"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="com.sinodata.bsm.center.service.config.PortalService"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="com.sinodata.bsm.center.bean.ResBean"%>
<%@page import="com.sinodata.bsm.center.purview.UserFunctionValidate"%>
<%@page import="com.sinodata.bsm.center.purview.FunctionConstants"%>
<%@page import="com.sinodata.bsm.center.user.UserUtil"%>
<%
String param = request.getParameter("args");
JSONObject parameter="".equals(param)?null:JSONObject.fromObject(param);
long t  = System.currentTimeMillis();
%>
<script type="text/javascript">
	$(document).ready(function(){
		var n2 = '<%=t%>';
		if($("#initFlag<%=t%>").val()!='true'){
			var valueSpan = $("span[name='healthValue']");
			//组件多个时 避免重复渲染
			if(valueSpan.html()==""){
				$.each(valueSpan,function(index,ob){
					var id = $(ob).attr('id');
					var value = $(ob).attr('value');
					$(ob).raty({
						start: value/20,
						readOnly:  true,
						hintList:[ ''+value,''+value,''+value,''+value,''+value],
						path: '${pageContext.request.contextPath}/js/raty/img/'
						
					});
				});
			}
		}
		$("#initFlag<%=t%>").val("true");
	});

			
</script>
<div>
	<div  class="blockDiv" style="background-color: #F6F7F9;border:1px solid #E2EAEC; height:21px;">
		<span class="menuTitle" style="width:33%">资源名称</span>
 	  	<span class="menuTitle" style="width:33%">主机IP</span>
 	  	<span class="menuTitle" style="width:33%">健康度</span>
 	</div>
 <%
 	int limitNumber=10;
 	String order ="asc" ;
	if(parameter!=null){
	  		 limitNumber =Integer.parseInt(parameter.getString("PARAM_limitsNum"));
	  		 order =parameter.getString("PARAM_order").equals("high")?"desc":"asc";
	 } 
	//当前用户可访问的资源
	
 	StringBuffer sql =new StringBuffer("select * from( select r.* from res r where r.deleted = 0 and r.res_type_id in (select id from res_type start with id in ");
 	sql.append("(select res_type_id    from moti_restype_rel  where self_flag = 1 and MOIT_TYPE_ID <=40000 ) connect by parent_id = prior id)   ");
 	UserUtil util= UserUtil.getInstance();
 	if(!util.isSysAdmin(util.getCurrentUserId())){
 	    List<Long> authScopeList = UserFunctionValidate.getResIdListForUser(FunctionConstants.VIEW_RES);
 	    StringBuffer currentUserResSql = new StringBuffer("(");
 	    for(int i=0;i<authScopeList.size();i++){
 	        Long resId = authScopeList.get(i);
 	        currentUserResSql.append(i==(authScopeList.size()-1)?resId+")":resId+",");
 	    }
 	    sql.append(" and r.id in (  select id from res where id in "+currentUserResSql.toString()+"  union  ");
 		sql.append(" select end_id from res_relation rel   start with start_id in "+currentUserResSql.toString() +" connect by prior end_id=start_id ) ");
 	}
 	sql.append(" order by r.health_degree "+order+") where rownum<="+limitNumber+" ");
 	PortalService service = SpringContextHolder.getBean(PortalService.class);
 	List<Map<String,Object>> list = service.findListBySql(sql.toString());
 	 
 	for(int i=0;i<list.size();i++){
 	  Map<String,Object> map =list.get(i);
 	  Long resId = Long.parseLong(map.get("id".toUpperCase()).toString());
 	  ResBean bean =  ResBean.get(resId);
 	  if(bean==null){
 	  	continue;
 	  }
 	  Res res = bean.res();
 	
%>
 	  <div class="valueDiv" style="background-color: <% if(i%2!=0){out.println("#F6F7F9");}else{out.println("#FFFFFF");} %>;line-height:20px;">
 	  	<span style="width:33%; height:20px; display:block; float:left;  " title="<%=res.getName() %>"><a href="${pageContext.request.contextPath}/resource/res-query!view.action?id=<%=res.getId() %>&pId=0&viewId=" target="_blank"><%=res.getName() %></a></span>
 	  	<span style="float:right;width:33%; height:20px; display:block;" id="health<%=i %><%=t%>" name="healthValue" value="<%=res.getHealthDegree() %>" ></span>
 	  	<span style="float:right; height:20px; width:33%; display:block;"><%=res.getIp() %></span>
 	  </div>
 	  
 	  <%
 	}
%>
<input type="hidden" id="initFlag<%=t%>" value="false">
</div>
